package com.huaxin.hxmoduleworkorder.service.impl;

import com.huaxin.hxmoduleworkorder.dto.response.InspectionReportDTO;
import com.huaxin.hxmoduleworkorder.models.InspectionOrderItem;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class AiSuggestionServiceImpl {
    // 示例：基于规则的 AI 建议（适合初期）
    public String generateAiSuggestion(List<InspectionOrderItem> items) {
        long abnormalCount = items.stream().filter(i -> "异常".equals(i.getResultStatus())).count();

        if (abnormalCount == 0) {
            return "本次巡检所有项目均正常，设备运行良好，建议继续保持定期维护。";
        } else {
            return "发现 " + abnormalCount + " 项异常，建议尽快安排专项检修，避免故障扩大。重点关注：" +
                    items.stream()
                            .filter(i -> "异常".equals(i.getResultStatus()))
                            .map(InspectionOrderItem::getName)
                            .collect(Collectors.joining("、")) + "。";
        }
    }
}
